const express = require('express')
const { expressjwt: jwt } = require('express-jwt')
const cors = require('cors')
const path = require('path');
const { Errordeal, ErrorGloab } = require('./middle/error')
const config = require('./config/config')
const bodyParser = require('body-parser')
const swagger = require('./proto/swagger')
const app = express()
const { newApp } = require('./proto/napp')
let _app = new newApp(app)

//中间件
app.use(jwt({ secret: config.tokenObject.JWTKey, algorithms: ["HS256"] }).unless({ path: ["/", "/swagger", "/login", "/backhome"] }));
app.use(Errordeal);
var jsonParser = bodyParser.json()
app.use(jsonParser)
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.use(urlencodedParser)
app.use(cors());
app.use(express.static(path.join(__dirname, 'staticFile')));


//自定义路由 
_app.use(require('./routes/login')).descri('登陆接口');
_app.use('/user', require('./routes/user')).descri('用户相关接口');









//swagger
app.get('/swagger', (req, res, next) => {
    swagger(req, res, _app)
})
app.use(ErrorGloab);
app.listen(config.httpPort, () => {
    console.log(`Server Started on ${config.httpPort}`);
})

